package org.example.day06;

import java.util.concurrent.atomic.AtomicInteger;

/**
 *  第二章节:2.3.2.4: 使用Atomic原子类进行i++操作实现原子性
 *      原子类型：没有锁的情况下做到线程安全
 **/
public class MyThread8 extends Thread{
    //原子类
    private AtomicInteger count = new AtomicInteger(0);

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println(count.incrementAndGet());
        }
    }

    public static void main(String[] args) {
        MyThread8 m8 = new MyThread8();
        Thread t1 = new Thread(m8);
        t1.start();
        Thread t2 = new Thread(m8);
        t2.start();
        Thread t3 = new Thread(m8);
        t3.start();
        Thread t4 = new Thread(m8);
        t4.start();
        Thread t5 = new Thread(m8);
        t5.start();
    }
}
